package top.lixunda.ecommerce.server.good.api.entity.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;
import top.lixunda.common.utils.ObjectValidators;
import top.lixunda.ecommerce.server.good.api.entity.db.EnshrineStoreDO;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 店铺收藏数据VO
 *
 * @author Xumda
 * @version time:2020/1/7 15:25
 */
@Data
@ApiModel("店铺收藏数据VO")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class EnshrineStoreVO {

    /**
     * 唯一id
     */
    @ApiModelProperty(value = "唯一id")
    private Integer id;

    /**
     * 收藏用户id
     */
    @ApiModelProperty(value = "收藏用户id")
    private Integer userId;

    /**
     * 用户名称
     */
    @ApiModelProperty(value = "用户名称")
    private String userName;

    /**
     * 收藏的店铺id
     */
    @ApiModelProperty(value = "收藏的店铺id")
    private Integer storeId;

    /**
     * 收藏的店铺名称
     */
    @ApiModelProperty(value = "收藏的店铺名称")
    private String storeName;

    /**
     * 收藏时间
     */
    @ApiModelProperty(value = "收藏时间")
    private LocalDateTime time;

    /**
     * 数据转换，DO转VO
     *
     * @param enshrineStoreDO EnshrineStoreDO
     * @return EnshrineStoreVO
     */
    @ApiModelProperty(hidden = true)
    @JsonIgnore
    public static EnshrineStoreVO fromEnshrineStoreDO(EnshrineStoreDO enshrineStoreDO) {
        if (enshrineStoreDO == null) {
            return null;
        }
        EnshrineStoreVO vo = new EnshrineStoreVO();
        BeanUtils.copyProperties(enshrineStoreDO, vo);
        return vo;
    }

    /**
     * 数据转换，DO转VO
     *
     * @param list EnshrineStoreDO列表
     * @return EnshrineStoreVO列表
     */
    @ApiModelProperty(hidden = true)
    @JsonIgnore
    public static List<EnshrineStoreVO> fromEnshrineStoreDO(List<EnshrineStoreDO> list) {
        if (ObjectValidators.isEmpty(list)) {
            return Collections.emptyList();
        }
        List<EnshrineStoreVO> voList = new ArrayList<>(list.size());
        for (EnshrineStoreDO storeDO : list) {
            voList.add(fromEnshrineStoreDO(storeDO));
        }
        return voList;
    }

}
